package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/7.
 */
@HttpInlet(Conn.INLET_GET_SPECIAL_SALE)
public class GetSpecialSale extends JTAsyGet<GetSpecialSale.Info> {

    public String token = JTApplication.jtPreferences.readToken();

    public GetSpecialSale(AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        JSONObject body = apiTYF.optJSONObject("body");

        Info info = new Info();

        info.msg = head.optString("msg");

        JSONArray list = body.optJSONArray("columnlist");

        if(list != null){

            for(int i = 0;i<list.length();i++){

                SpecialSaleItem item = new SpecialSaleItem();

                JSONObject mItem = list.optJSONObject(i);

                item.id = mItem.optString("ID");

                item.title = mItem.optString("TITLE");

                item.des = mItem.optString("DES");

                item.pic = mItem.optString("PIC");

                info.specialSaleList.add(item);

            }

        }

        return info;

    }

    public static class Info {

        public String msg;

        public List<SpecialSaleItem> specialSaleList = new ArrayList<>();

    }

    public static class SpecialSaleItem{

        public String id;

        public String title;

        public String des;

        public String pic;

    }

}
